<template>
    <div class="newsinfo-container">
        <h1 class="title">{{newinfo.title}}</h1>
        <p class="subtitle">
            <span>发表时间：{{newinfo.time}}</span>
            <span>点击：{{newinfo.num}}次 </span>
        </p>

        <hr>

        <div class="content" v-html="newinfo.content">
        </div>
        <comment-box :id="this.id"></comment-box>
    </div>
</template>

<script>
    import comment from '../subcomponents/commnet.vue'

    export default {
        data(){
            return {
                id:this.$route.params.id,
                newinfo:[]
            }
        },
        created(){
          this.getNewInfo();
        },
        methods:{
            getNewInfo(){
                var sendData={id:this.id};
                this.$http.jsonp('http://localhost:80/vue-cms/2.php/newinfo',{params :sendData})
                    .then(data=>{
                        if(data.status === 200){
                            //console.log(data)
                            this.newinfo = JSON.parse(data.bodyText);
                            //注意这个返回的值仍然是一个字符串，这样子就会导致其实返回不了正确的结果，需要用JSON.parse对其进行一次处理，这样子就可以得到
                            //正确的JSON格式的字符串
                            //console.log(this.newinfo);
                        }else {
                            Toast("加载数据失败")
                        }
                    })
            }
        },
        components:{
            //用来注册子组件的节点
            'comment-box':comment
        }
    }
</script>

<style scoped>
    .newsinfo-container{
        padding: 0 4px;
    }
    .newsinfo-container .title{
        font-size: 16px;
        text-align: center;
        margin: 15px 0;
        color: red;
    }
    .newsinfo-container .subtitle{
        font-size: 12px;
        color:blue;
        display: flex;
        justify-content: space-between;
    }
    .newsinfo-container .content img{
        width: 100%;
    }
</style>